package cn.tx.trans;

import cn.tx.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo1 {


    public static void trans1() throws SQLException {
        String sql="update account t set t.balance=t.balance-10000 where t.ID=1";
        String sql1="update account t set t.balance=t.balance+10000 where t.ID=2";

        Connection conn = DBUtil.getConn();
        int transactionIsolation = conn.getTransactionIsolation();
        System.out.println(transactionIsolation);

        PreparedStatement statement = null;
        PreparedStatement statement1= null;
        try {
            conn.setAutoCommit(false);


            statement = conn.prepareStatement(sql);
            statement1 = conn.prepareStatement(sql1);


        } catch (SQLException e) {
            e.printStackTrace();

        } finally {
            DBUtil.closeRes(statement);
            DBUtil.closeRes(statement1);
            //事务回滚

        }

    }

    public static void main(String[] args) throws SQLException {
        trans1();
    }
}
